﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace Nova_BLL
{
    public class Group
    {
        DataSet ds = null;
        int i = 0;
        Nova_DAL.Group Nova_DAL_Group = new Nova_DAL.Group();



        ///<summary>
        ///获取工作组列表
        ///</summary>
        ///<param name="sQL">SQL</param>
        ///<returns>返回DataSet</returnss>
        ///Writer：[王成友]
        ///Create Date： [2010-5-20]
        ///</summary>
        public DataSet DataListGroup()
        {
            ds = Nova_DAL_Group.DataListGroup();
            return ds;
        }

        ///<summary>
        ///获取工作组列表
        ///</summary>
        ///<param name="vGroupNo">vGroupNo</param>
        ///<returns>返回DataSet</returnss>
        ///Writer：[王成友]
        ///Create Date： [2010-5-26]
        ///</summary>
        public DataSet DataListGroup(string vGroupNo)
        {
            ds = Nova_DAL_Group.DataListGroup(vGroupNo);
            return ds;
        }

        ///<summary>
        ///获取用户工作组列表
        ///</summary>
        ///<param name="sQL">SQL</param>
        ///<returns>返回DataSet</returnss>
        ///Writer：[王成友]
        ///Create Date： [2010-5-20]
        ///</summary>
        public DataSet DataListUserGroup(string vUserNo)
        {
            ds = Nova_DAL_Group.DataListUserGroup(vUserNo);
            return ds;
        }

        ///<summary>
        ///增加工作组
        ///</summary>
        ///<param name="sQL">vGroupNo,vGroupName</param>
        ///<returns>返回int,0失败,1成功,2已经存在工作编号</returnss>
        ///Writer：[王成友]
        ///Create Date： [2010-5-20]
        ///</summary>
        public int AddGroup(Nova_MOD.Group Group)
        {
            if (Nova_DAL_Group.CheckGroupNoExists(Group.vGroupNo) > 0)
            {
                i = 2;
            }
            else
            {
                try
                {

                    i = Nova_DAL_Group.AddGroup(Group);
                }
                catch (Exception ex)
                {
                    Console.Write(ex.ToString());
                }
            }
            return i;
        }


        ///<summary>
        ///修改工作组
        ///</summary>
        ///<param name="sQL">vGroupNo,vGroupName,id</param>
        ///<returns>返回int,0失败,1成功,2已经存在该工作编号</returnss>
        ///Writer：[王成友],editor:[kitty]
        ///Create Date： [2010-5-20]
        ///</summary>
        public int UpdateGroup(Nova_MOD.Group Group, string oldGroupNo)
        {
            if (Nova_DAL_Group.CheckGroupNoExists(Group.vGroupNo, oldGroupNo) > 0)
            {
                i = 2;
            }
            else
            {
                try
                {
                    i = Nova_DAL_Group.UpdateGroup(Group);
                }
                catch (Exception ex)
                {
                    Console.Write(ex.ToString());
                }
            }
            return i;
        }

        ///<summary>
        ///删除工作组
        ///</summary>
        ///<param name="sQL">id</param>
        ///<returns>返回int,0失败,1成功</returnss>
        ///Writer：[王成友]
        ///Create Date： [2010-5-20]
        ///</summary>
        public int DeleteGroup(string id)
        {
            try
            {
                i = Nova_DAL_Group.DeleteGroup(id);
            }
            catch (Exception ex)
            {
                Console.Write(ex.ToString());
            }
            return i;
        }

        ///<summary>
        ///删除多个工作组
        ///</summary>
        ///<param name="sQL">id</param>
        ///<returns>返回int,0失败,1成功</returnss>
        /// writer:[Kitty]
        /// Create Date:[2010-5-27]
        ///</summary>
        public int DeleteAllGroup(string listGroupNo)
        {
            try
            {
                i = Nova_DAL_Group.DeleteAllGroup(listGroupNo);
            }
            catch (Exception ex)
            {
                Console.Write(ex.ToString());
            }
            return i;
        }

        //public string GetParameter<T>(List<T> value)
        //{
        //    if (value.Count > 0)
        //    {
        //        StringBuilder builder = new StringBuilder();
        //        builder.Append("(");
        //        foreach (T local in value)
        //        {
        //            if (local is string)
        //            {
        //                builder.Append(string.Format("N'{0}',", local.ToString().Replace("'", "''")));
        //            }
        //            else
        //            {
        //                if ((!(local is int) && !(local is decimal)) && (!(local is double) && !(local is float)))
        //                {
        //                    throw new Exception(string.Format("{0} is an unacceptable datatype in List", local.GetType()));
        //                }
        //                builder.Append(string.Format("{0},", local));
        //                continue;
        //            }
        //        }
        //        builder.Remove(builder.Length - 1, 1);
        //        builder.Append(")");

        //        return builder.ToString();
        //    }
        //    return string.Empty;
        //}        

    }
}
